// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CXFormsElementRepeat.
//   $Id$



#ifndef __REPEATUI_H
#define __REPEATUI_H 1

#pragma once

#include "NodesetBindingUI.h"

#define CXFORMSELEMENTREPEAT_EVENTS_LENGTH 2

class CXFormsElementRepeat 
	: public CXFormsElementNodesetBinding
	//,public IUIRepeatEvents
	,public ISerialiseViewlink
{
public:
	CXFormsElementRepeat();
	virtual ~CXFormsElementRepeat();

	DECLARE_GET_CONTROLLING_UNKNOWN();
	BEGIN_COM_MAP(CXFormsElementRepeat)
		COM_INTERFACE_ENTRY(ISerialiseViewlink)
		COM_INTERFACE_ENTRY2(IUnknown, IElementBehavior)
		COM_INTERFACE_ENTRY_CHAIN(CXFormsElement)
	END_COM_MAP()

	STDMETHOD(SerialiseViewlink)(IXMLDOMDocument *pSerialisationDOM, IXMLDOMNode *pThis);
	STDMETHOD(GetProperty)(BSTR sProperty, BSTR * sValue);
	//STDMETHOD(SetProperty)(BSTR sProperty, BSTR sValue);
	STDMETHOD(Detach)();
	HRESULT put_iterations(unsigned long lVal);
	virtual HRESULT attachEvents(IHTMLDocument3 * pDoc3 = 0);
	virtual CImpl* CreateImpl();
	virtual CXFormsParse* CreateParse(CImpl* pImpl);
	virtual HRESULT getUI(CComBSTR &sHtml);
//	virtual HRESULT show(BOOL bShow);
	
	//IUIRepeatEvents
	virtual HRESULT InitBehaviour();
	virtual HRESULT formControlInitialize();
	virtual HRESULT ElementReady(void);

	HRESULT render(void);
	// Bug 1021 - The repeat shouldn't reflect the state of its node bindings 
	// that is the responsibility of the repeat iterations. So these methods do 
	// nothing
	virtual HRESULT SetClassProperty(bool bEnabled, bool bReadOnly, bool bValid, bool bRequired);
	virtual HRESULT required(BOOL bRequired);
	virtual HRESULT enable(BOOL bShow);
	virtual HRESULT readonly(BOOL bReadOnly);
	virtual HRESULT valid(BOOL bValid);

private:
	unsigned long m_lIterations;
	CComPtr<IXMLDOMNodeList> m_pTRowContent;

	//array storing event cookies.
	//	these are the ids given to us by 
	//	RegisterEvent.
	long m_alEventCookies[CXFORMSELEMENTREPEAT_EVENTS_LENGTH];
	//The event cookies are assigned on an
	//	object-by-object basis, however, 
	//	the names can be static.
	static const CComBSTR * const sm_asEventNames[CXFORMSELEMENTREPEAT_EVENTS_LENGTH];
	bool m_bRendered;
	static unsigned long smRepeatsProcessingElementReady;

	// Bug 1018: Do not add actions to the grid repeat UI (they cause extraneous columns).
	bool IsAction(IXMLDOMNode *pNode);
	HRESULT AddTableRowIterations(unsigned long lVal);
	HRESULT AddNormalIterations(unsigned long lVal);
	HRESULT AddColumnIterations(unsigned long lVal);

	HRESULT RemoveTableRowIterations(unsigned long lVal);
	HRESULT RemoveNormalIterations(unsigned long lVal);
	HRESULT RemoveColumnIterations(unsigned long lVal);
	CComBSTR m_sColumnContent;
	//<summary>
	//	Returns the first child node of pParent that is a table
	//</summary>
	HRESULT GetFirstTableChild(IHTMLDOMNode * pParent,CComQIPtr<IHTMLTable> & pTable) const;
	bool m_bDisplayAsColumns;
	HRESULT PrepareRowContent(CComBSTR & sHtml);
	HRESULT PrepareColumnContent(CComBSTR & sHtml);
};

#endif // __REPEATUI_H
